package com.hanbang.taitaigou.ui.activity.aboutme.setting;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.hanbang.taitaigou.R;
import com.hanbang.taitaigou.model.GetContact;
import com.hanbang.taitaigou.ui.activity.base.BaseActivity;
import com.hanbang.taitaigou.utils.http.HttpCallBack;
import com.hanbang.taitaigou.utils.http.HttpRequestParams;
import com.hanbang.taitaigou.utils.http.JsonHelper;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 关于我们
 * Created by fanxin on 2016/3/22.
 */
public class AboutMeSetUpAboutUsActivity extends BaseActivity {

    private WebView wv_web;
    private GetContact getContact = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aboutme_set_up_about_us);
        initView();
        setOnClickListener();
        getValidate();
    }

    /*
     * 设置点击事件
     */
    private void setOnClickListener() {


    }

    @SuppressWarnings("unused")
    private View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {

                default:
                    break;
            }
        }
    };

    /*
     * 初始化view
     */
    private void initView() {
        // 设置顶部的标题
        setTop(null, 0, getString(R.string.top_set_us), null, 0);
        setBackArrows(findViewById(R.id.top_bar_left_iv));

        wv_web = (WebView)findViewById(R.id.wv_web);

    }

    /*
     * 关于我们接口
     */
    private void getValidate() {
        HttpRequestParams httpRequestParams = new HttpRequestParams("GetAbout");
        httpRequestParams.addUserId(userData);
        httpManager.post(httpRequestParams, new HttpCallBack<String>(this, "正在加载...") {

            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                try {

                    JSONObject jsonObject = new JSONObject(result);
                    if(jsonObject.getInt("status") == 1) {
                        JSONArray js = jsonObject.getJSONArray("result");
                        if(js.length()>0){
                            getContact = JsonHelper.parseObject(js.getJSONObject(0),GetContact.class);
                            if(getContact != null){
//                                wv_web.loadDataWithBaseURL(null,getContact.getContent(),"utf-8",null,null);
                                String ss = getContact.getContent();
//                                wv_web.loadData(ss, "text/html", "UTF-8");
//                                wv_web.getSettings().setLoadWithOverviewMode(true);
//                                wv_web.getSettings().setUseWideViewPort(true);
                                wv_web.loadDataWithBaseURL(null, ss, "text/html", "utf-8", null);
                                wv_web.getSettings().setJavaScriptEnabled(true);
                                wv_web.setWebChromeClient(new WebChromeClient());
                            }
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
